package moreHealthControl;

import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import moreHealthException.StringLengthException;
import moreHealthModel.Student.Student.Disease;
import moreHealthView.StudentInformationForm;


//Get the Disease selected from the ListBox.
public class StudentFormListBoxListener implements ListSelectionListener
		{
			//ATTRIBUTES ======================================
			
			//The index of the First Disease in the List Box is 0, so on and so forth. 
			String  diseaseSelectionIndicex_="";
			
			//Disease Name of the Selected Disease List.
			Disease diseaseSelecttionValuex_;
			
			//The key used in the Hash-map to identify the Component in the frame.
			//The components currently in used are 1. TextFields, 2. List Box, 3. Radio Buttons. 
			String  diseaseLabelx_="";
			
			
			//CONSTRUCTORS ======================================
			//INTENT: Get the disease student selected.
			//PRE-CONDITION : 
				//1. At least One disease should be selected from the Disease List.
			//POST-CONDITION: 
				//1. Marks the which component triggered the event. In this case it is the Disease List box. 
			public StudentFormListBoxListener (String diseaseLabel) {
				this.diseaseLabelx_ = diseaseLabel;
			}

			
			//INTENT: Stores the Diseases selected by the Student in the Hash. Later this is used to calculate the 
			//		  Seriousness factor of the student. 
			//PRE-CONDITION : 
				//1. One of the disease should be selected from the Disease List.
				//2. For the even to get fired Always left mouse click on the list box. 
				//   DO NOT JUST PRESS ENTER WITH THE FOCUS ON THE LIST BOX. 
			//POST-CONDITION: 
				//1. Adds to a Hash-map with a key[disease] and values [Disease Object].
			@Override
			public void valueChanged(ListSelectionEvent e)
				{
					
					//Nothing was selected
					if (StudentInformationForm.diseaselist.getSelectedIndex() == -1)
						{
							try
								{
									throw new StringLengthException("Please select a Disease from the listddddd");
								} catch (StringLengthException e1)
								{
									// TODO Auto-generated catch block
									System.out.println(e1.getMessage());
								}
						}
					
					else 
						{//Store the Student selected disease in the hash map for Seriousness factor calculation. 
							this.diseaseSelectionIndicex_= Integer.toString(StudentInformationForm.diseaselist.getSelectedIndex());
							this.diseaseSelecttionValuex_= (Disease) StudentInformationForm.diseaselist.getSelectedValue();
							StudentInformationForm.studentInfoFormIp.put(this.diseaseLabelx_, this.diseaseSelecttionValuex_);
						}				
				}
			}

